home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 5_2.lha / 5_2 / 5_2b2.c < prev    next >
Text File  |  1993-08-08  |  530b  |  33 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. / find a word within the tree
  6. include <tree.h>
  7. include <string.h>
  8.  
  9. node *tree:: findnode(char *s)
  10.  
  11.    tnode *cur = head;
  12.  
  13.    for (;;)
  14. {
  15. if (!cur)
  16.     return 0;
  17.  
  18. int cmp = strcmp(s, cur->tword);
  19.  
  20. // check the left subtree
  21. if (cmp < 0)
  22.     cur = cur->left;
  23.  
  24. // check the right subtree
  25. else if (cmp > 0)
  26.     cur = cur->right;
  27.  
  28. // equal, found it
  29. else /* if (cmp == 0) */
  30.     return cur;
  31. }
  32.  
  33.